﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using GBlog.Core.Data;
using GBlog.Core.Entities;

namespace GBlog.Core.Service.Default
{
    public class ErrorService : IErrorService
    {
        IRepository<Error> Repository;
        IUserService User;
        public ErrorService(IRepository<Error> Repository, IUserService User)
        {
            this.Repository = Repository;
            this.User = User;
        }

        public void Report(string Action, string Controller, string Referrer, string Url)
        {
            Error error = new Error();
            error.Action = Action;
            error.Controller = Controller;
            error.Referrer = Referrer;
            error.Url = Url;
            if (User.Current != null && User.Current.ID != 0)
            {
                error.UserID = User.Current.ID;
            }
            Repository.Insert(error);
        }
    }
}
